package com.t2c.tibetantochinese.search;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.t2c.tibetantochinese.R;
import com.t2c.tibetantochinese.moudle.SearchNetBean;
import com.t2c.tibetantochinese.utils.CommonUtil;

/**
 * Created by zoulu on 16/12/5.
 * 从网络搜索获取数据的adapter
 */
public class SearchNetAdapter extends BaseAdapter{
    private Context mContext;
    private SearchNetBean searchNetBean;

    public SearchNetAdapter(Context context, SearchNetBean searchNetBean){
        this.mContext  = context;
        this.searchNetBean = searchNetBean;
    }
    @Override
    public int getCount() {
        return searchNetBean.getData() != null ? searchNetBean.getData().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if(convertView == null ) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.search_net_item, null);
            holder =new Holder();
            holder.chinese = (TextView)convertView.findViewById(R.id.chinese);
            holder.tibetan = (TextView)convertView.findViewById(R.id.tibetan);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.chinese.setText(searchNetBean.getData().get(position).getContent());
        holder.tibetan.setTypeface(CommonUtil.getTibetanType(mContext));
        holder.tibetan.setText(searchNetBean.getData().get(position).getTibetContent());

        return convertView;
    }

    private class Holder{
        TextView chinese;
        TextView tibetan;
    }
}
